package hot.pay.office.service.impl;

import com.sunmnet.framework.exception.PlatformException;
import com.sunmnet.framework.expands.office.excel.ExcelIO;
import com.sunmnet.framework.utils.file.FileUtils;
import hot.pay.exception.HotErrMsgEnum;
import hot.pay.office.service.IReadExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

@Service("ReadExcelServiceImpl")
public class ReadExcelServiceImpl implements IReadExcelService {


	/***
	 * 读取excel文件
	 * @param path
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Map<String, Object>> read2Map(String path) throws Exception {
		List<Map<String, Object>> dataList = null;
		try (InputStream in = FileUtils.getResourceAsStream(path)) {
			dataList = ExcelIO.read2Map(in);
		}catch (Exception ex){
			throw new PlatformException(HotErrMsgEnum.IMPORT_EXCEL);
		}
		return dataList;
	}

}
